<template>
  <div>
    <el-container>
      <el-header class="classHeader">
        <div class="title">
          云E办
        </div>
        <el-button style="display: inline-block; margin-left: 80%"
                   @click="toChat"
                   size="big"
                   type="info"
                   icon="el-icon-message-solid"
                   circle></el-button>

        <div style="width: 200px">

          <el-dropdown @command="handleCommand" class="headerInfo">
            <span class="el-dropdown-link">
              {{ user.name }}
              <i>
                <img :src="user.userFace">
              </i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
              <el-dropdown-item command="setting">设置</el-dropdown-item>
              <el-dropdown-item command="logout">注销登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu router unique-opened>
            <el-submenu :index="index+''" v-for="(item,index) in routes"
                        :key="index"
                        v-if="!item.hidden">
              <template slot="title">
                <i :class="item.iconCls" style="color: mediumaquamarine; margin-right: 5px"></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item :index="children.path"
                            v-for="(children,index) in item.children">
                {{ children.name }}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path != '/home'">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ this.$router.currentRoute.name }}</el-breadcrumb-item>
          </el-breadcrumb>
          <div class="homeWelcome" v-if="this.$router.currentRoute.path == '/home'">
            欢迎来到 云E办
          </div>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  methods: {
    toChat(){
      this.$router.push('/chat');
    },
    handleCommand(command) {
      if (command == 'logout') {
        //先弹出提示框
        this.$confirm('您确定要注销登陆吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          //注销登录
          this.postRequest('/logout');
          //清除内存
          window.sessionStorage.removeItem('user');
          window.sessionStorage.removeItem('tokenStr');
          //清除菜单信息
          this.$store.commit('initRoutes', []);
          //跳转到登录页
          this.$router.replace('/');

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消注销操作'
          });
        });
      }
      if (command == 'userInfo'){
        this.$router.push('/userInfo');
      }

    }
  },
  computed: {
    routes() {
      return this.$store.state.routes;
    },
    user(){
      return this.$store.state.currentAdmin;
    }
  },
  data() {
    return {
      // user: JSON.parse(window.sessionStorage.getItem('user'))
    }
  }

}
</script>

<style scoped>
.classHeader {
  background: #409eff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 15px;
  box-sizing: border-box;
}

.headerInfo {
  cursor: pointer;
  margin-right: 2%;
}

.classHeader img {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 5px;
}

.classHeader .title {
  font-size: 30px;
  font-family: 新宋体;
  color: white;
}

.homeWelcome {
  font-family: 新宋体;
  font-size: 30px;
  color: deepskyblue;
  margin: 50px;
}
</style>